package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Tabpe002Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Tabpe002Report {
	private String ano2;
	private String fimpl;
	private String par1;
	private String par2;
	private String par3;
	private String cota;
	private String cabecaCet;
	private String cabecaDet;
	private int dataCorrente;
	private Integer dintabMatfun; // DB
	private Integer dintabDatatu; // DB
	public String desc2;
	public String codele;
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicTabelas vwDvetab = new SicTabelas();
	// Classes includes
	Sisll001 sisll001 = new Sisll001();

	public Tabpe002Report() throws JRException, ParseException {
		inicializar();
	}

	public Tabpe002Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		cabecaCet = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaDet = "SECRETARIA ADJUNTA DE TECNOLOGIA DA INFORMACAO - SEATI";
		dataCorrente = 0;
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(0, 1, "lit_0_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 70, "Cabecacet", "X", "ZZZ999", "");
				report.adicionaCampo(117, 7, "lit_117_7", "C", "", "PAGINA:");
				report.adicionaCampo(0, 5, "nroPagina", "S", "ZZZ999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 2);
			{
				report.adicionaCampo(1, 60, "Cabecadet", "X", "", "");
				report.adicionaCampo(117, 14, "lit_117_14", "C", "", "REL.  TABPE002");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 3);
			{
				report.adicionaCampo(1, 9, "lit_1_9", "C", "", "DETRAN-MA");
				report.adicionaCampo(117, 5, "lit_117_5", "C", "", "DATA:");
				report.adicionaCampo(0, 8, "dataCorrente", "N", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 2);
			{
				report.adicionaCampo(1, 59, "lit_1_59", "C", "", "EMISSAO DO CADASTRO DE APOIO ==> TABELA 13 DE VENCIMENTO DO");
				report.adicionaCampo(65, 28, "lit_65_28", "C", "", "IPVA E DO SEGURO OBRIGATORIO");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 4);
			{
				report.adicionaCampo(1, 52, "lit_1_52", "C", "", "ANO  FINAL DA PLACA      1A. PARCELA     2A. PARCELA");
				report.adicionaCampo(57, 35, "lit_57_35", "C", "", "3A. PARCELA    COTA UNICA OU SEGURO");
				report.adicionaCampo(103, 9, "lit_103_9", "C", "", "MATRICULA");
				report.adicionaCampo(119, 11, "lit_119_11", "C", "", "ATUALIZACAO");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 8);
			{
				report.adicionaCampo(2, 4, "Ano2", "N", "", "");
				report.adicionaCampo(12, 1, "Fimpl", "N", "", "");
				report.adicionaCampo(27, 6, "Par1", "N", "99/99/9999", "");
				report.adicionaCampo(43, 6, "Par2", "N", "99/99/9999", "");
				report.adicionaCampo(57, 6, "Par3", "N", "99/99/9999", "");
				report.adicionaCampo(76, 6, "Cota", "N", "99/99/9999", "");
				report.adicionaCampo(104, 7, "Dintabmatfun", "N", "99/99/9999", "");
				report.adicionaCampo(122, 8, "Dintabdatatu", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
		}
		setCabecacet(cabecaCet);
		setCabecadet(cabecaDet);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getAno2() {
		return ano2;
	}

	public void setAno2(String ano2) throws ParseException {
		this.ano2 = ano2;
		report.adicionaValorReport("Ano2", ano2);
	}

	public String getFimpl() {
		return fimpl;
	}

	public void setFimpl(String fimpl) throws ParseException {
		this.fimpl = fimpl;
		report.adicionaValorReport("Fimpl", fimpl);
	}

	public String getPar1() {
		return par1;
	}

	public void setPar1(String par1) throws ParseException {
		this.par1 = par1;
		report.adicionaValorReport("Par1", par1);
	}

	public String getPar2() {
		return par2;
	}

	public void setPar2(String par2) throws ParseException {
		this.par2 = par2;
		report.adicionaValorReport("Par2", par2);
	}

	public String getPar3() {
		return par3;
	}

	public void setPar3(String par3) throws ParseException {
		this.par3 = par3;
		report.adicionaValorReport("Par3", par3);
	}

	public String getCota() {
		return cota;
	}

	public void setCota(String cota) throws ParseException {
		this.cota = cota;
		report.adicionaValorReport("Cota", cota);
	}

	public String getCabecacet() {
		return cabecaCet;
	}

	public void setCabecacet(String cabecaCet) throws ParseException {
		this.cabecaCet = cabecaCet;
		report.adicionaValorReport("Cabecacet", cabecaCet);
	}

	public String getCabecadet() {
		return cabecaDet;
	}

	public void setCabecadet(String cabecaDet) throws ParseException {
		this.cabecaDet = cabecaDet;
		report.adicionaValorReport("Cabecadet", cabecaDet);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	} // /

	public String getDesc2() {
		return this.par1 + this.par2 + this.par3 + this.cota;
	}

	public void setDesc2(String desc2) throws ParseException {
		this.desc2 = desc2;
		this.par1 = UtilBean.subStr(desc2, 0, 6);
		report.adicionaValorReport("Par1", UtilBean.subStr(desc2, 0, 6));
		this.par2 = UtilBean.subStr(desc2, 6, 6);
		report.adicionaValorReport("Par2", UtilBean.subStr(desc2, 6, 6));
		this.par3 = UtilBean.subStr(desc2, 12, 6);
		report.adicionaValorReport("Par3", UtilBean.subStr(desc2, 12, 6));
		this.cota = UtilBean.subStr(desc2, 18, 6);
		report.adicionaValorReport("Cota", UtilBean.subStr(desc2, 18, 6));
	} // /

	public String getCodele() {
		return this.ano2 + this.fimpl;
	}

	public void setCodele(String codele) throws ParseException {
		this.codele = codele;
		this.ano2 = UtilBean.subStr(codele, 0, 4);
		report.adicionaValorReport("Ano2", UtilBean.subStr(codele, 0, 4));
		this.fimpl = UtilBean.subStr(codele, 4, 1);
		report.adicionaValorReport("Fimpl", UtilBean.subStr(codele, 4, 1));
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Integer getDintabMatfun() {
		return dintabMatfun;
	}

	public void setDintabMatfun(Integer dintabMatfun) throws ParseException {
		this.dintabMatfun = dintabMatfun;
		report.adicionaValorReport("dintabMatfun", dintabMatfun);
	}

	public Integer getDintabDatatu() {
		return dintabDatatu;
	}

	public void setDintabDatatu(Integer dintabDatatu) throws ParseException {
		this.dintabDatatu = dintabDatatu;
		report.adicionaValorReport("dintabDatatu", dintabDatatu);
	}

}
